package com.example.study.controller;


import com.example.study.dao.User;
import com.example.study.utils.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "json")
public class JsonController {

    @RequestMapping(value = "/user")
    public User getUser(){
        return new User(1,"xll","123");
    }

    @RequestMapping(value = "userList")
    public List<User> getUserList(){
        List<User> userList = new ArrayList<>();
        User user = new User(2,"xll","123");
        User user1 = new User(3,"lcy","234");
        userList.add(user1);
        userList.add(user);
        return userList;
    }


    @RequestMapping(value = "map")
    public Map<String,Object> getUserMap(){
        Map<String ,Object> map = new HashMap<>(3);
        User user = new User(1,"xll","123");
        map.put("用户",user);
        map.put("贯籍","江苏淮安");
        return map;
    }


    @RequestMapping(value = "jsonUser")
    public JsonResult jsonUser(){
        User user = new User(1,"xll","123");
        return new JsonResult<>(user);
    }


    @RequestMapping(value = "jsonUserList")
    public JsonResult jsonUserList(){
        List<User> userList = new ArrayList<>();
        User user = new User(2,"xll","123");
        User user1 = new User(3,"lcy","234");
        userList.add(user1);
        userList.add(user);
        return new JsonResult<>(userList,"获取用户列表成功");
    }


    @RequestMapping(value = "jsonMap")
    public JsonResult jsonMap(){
        Map<String ,Object> map = new HashMap<>(3);
        User user = new User(1,"xll","123");
        map.put("用户",user);
        map.put("贯籍","江苏淮安");
        return new JsonResult<>(map);
    }


}
